package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Banner;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
* @author 邵康
* @date 2021/11/23 19:49
*/
@CrossOrigin
@RestController
@RequestMapping("/banner")
@Api(tags = "轮播图")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @ApiOperation("添加Banner  除了id其他都是必须的")
    @PostMapping("/add")
    public R<Void> add(Banner banner) {
        return bannerService.add(banner);
    }

    @ApiOperation("根据类型获取 Banner  若为主页传入 0  默认值为0")
    @GetMapping("/getBanner")
    public R<List<Banner>> getBanner(@RequestParam(defaultValue = "0") Integer typeId){
        return bannerService.getBanner(typeId);
    }

    @ApiOperation("delete")
    @GetMapping("/delete")
    public R<Void> delete(Integer id){
        return bannerService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update( Banner banner){
        return bannerService.update(banner);
    }

    @ApiOperation("pageSearch")
    @GetMapping("/page")
    public R<IPage<Banner>> page( @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer size){
        return bannerService.page(page,size);
    }

}
